﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GMS.MainClasses;
using GMS.ServiceFunctions.FunctionForControls;
using GMS.ServiceFunctions.Data;
using GMS.MainForm;
using GMS.Dinasty.Specifications;


namespace GMS.Dinasty.ReferenceGoods
{
    public partial class ReferenceGoods : ChildForms
    {
        private Specifications.Specifications SpecifForm;
        public ReferenceGoods()
        {
            InitializeComponent();


            StoredProcedures = new String[2];

            StoredProcedures[0] = "select * from Goods";
            StoredProcedures[1] = "[MakeRootNode]";
            //ConnectionString = "server=pavel;uid=pavel;pwd=123456;database=GMSDatabase";

        }

        public ReferenceGoods(Specifications.Specifications SForm)
        {
            InitializeComponent();
            SpecifForm = SForm;

            StoredProcedures = new String[2];

            StoredProcedures[0] = "select * from Goods";
            StoredProcedures[1] = "[MakeRootNode]";
        
        }

        FunctionForTreeView FFTV = new FunctionForTreeView();
        BindingSource bsMenu = new BindingSource();
        TreeNode SelectedNode = new TreeNode();

        ReturnData rd = new ReturnData();


        

        private void RefreshTreeView()
        {
            //bsMenu.DataSource = rd.ReturnDataSetDB(ConnectionString, StoredProcedures[0]);
            bsMenu.DataSource = MRF.ReturnDataSetDB(ConnectionString, StoredProcedures[0]);

            bsMenu.DataMember = "table";
            FFTV.FillTreeView(treeView1, bsMenu, "IdGoods", "IdId", "Caption");
            SelectedNode.Expand();
        }

        private void ReferenceGoods_Activated(object sender, EventArgs e)
        {
            RefreshTreeView();
        }

        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            groupBox2.Text = "Карточка - " + e.Node.Text;
        }

        private void acceptButton1_Click(object sender, EventArgs e)
        {
            SpecifForm.CaptionGood = treeView1.SelectedNode.Text;
            SpecifForm.IdGood = Convert.ToInt32(treeView1.SelectedNode.Tag);
        }
    }
}
